// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.assets.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.assets.controller.request.QueryAssetsDepartmentReq;
import com.liuxinlong.modules.assets.controller.request.UpdateAssetsDepartmentReq;
import com.liuxinlong.modules.assets.service.AssetsDepartmentService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.AssetsDepartment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 固资部门理控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2024-01-09
 */
@RestController
@RequestMapping("/assets/department")
public class AssetsDepartmentController {
    @Autowired
    private AssetsDepartmentService assetsDepartmentService;

    /**
     * 分页查询固资部门理信息列表
     *
     * @param req 请求信息
     * @return 固资部门理信息列表
     */
    @PostMapping("page")
    public BaseResp pageAssetsDepartmentList(@RequestBody QueryAssetsDepartmentReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("departmentName", req.getDepartmentName());
        queryMap.put("departmentSn", req.getDepartmentSn());
        queryMap.put("manageUser", req.getManageUser());
        List<Map<String, Object>> dataList = assetsDepartmentService.pageAssetsDepartmentInfo(queryMap);
        int totalNum = assetsDepartmentService.getAssetsDepartmentInfoCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询固资部门信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 新增固资部门信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增固资部门信息", business = LogBusinessConstants.ASSETS_DEPARTMENT, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addAssetsDepartmentInfo(@RequestBody UpdateAssetsDepartmentReq req) {
        AssetsDepartment assetsDepartment = new AssetsDepartment();
        assetsDepartment.setDepartment(req.getDepartment());
        assetsDepartment.setDepartmentSn(req.getDepartmentSn());
//        assetsDepartment.setManageUser(req.getManageUser());
        assetsDepartment.setRemark(req.getRemark());
        assetsDepartmentService.addAssetsDepartmentInfo(assetsDepartment);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增固资部门信息成功");
        return resp;
    }

    /**
     * 修改固资部门信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "修改固资部门信息", business = LogBusinessConstants.ASSETS_DEPARTMENT, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateAssetsDepartmentInfo(@RequestBody UpdateAssetsDepartmentReq req) {
        AssetsDepartment assetsDepartment = new AssetsDepartment();
        assetsDepartment.setId(req.getId());
        assetsDepartment.setDepartment(req.getDepartment());
        assetsDepartment.setDepartmentSn(req.getDepartmentSn());
//        assetsDepartment.setManageUser(req.getManageUser());
        assetsDepartment.setRemark(req.getRemark());
        assetsDepartmentService.updateAssetsDepartmentInfo(assetsDepartment);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改固资部门信息成功");
        return resp;
    }

    /**
     * 删除固资部门信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除固资部门信息", business = LogBusinessConstants.ASSETS_DEPARTMENT, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteAssetsDepartmentInfo(@RequestBody BaseDeleteReq req) {
        assetsDepartmentService.deleteAssetsDepartmentInfo(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除固资部门信息成功");
        return resp;
    }

    /**
     * 导出固资部门信息
     *
     * @param response response
     * @return 导出数据
     */
    @PostMapping("export")
    @LogAnnotation(value = "导出固资部门信息", business = LogBusinessConstants.ASSETS_DEPARTMENT, operateType = LogOperateConstants.OPERATE_EXPORT)
    public void exportAssetsInfo(@RequestBody QueryAssetsDepartmentReq req, HttpServletResponse response) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("departmentName", req.getDepartmentName());
        queryMap.put("departmentSn", req.getDepartmentSn());
        queryMap.put("manageUser", req.getManageUser());
        assetsDepartmentService.exportAssetsDepartment(queryMap, response);
    }

}
